﻿using System;
using System.Collections.Generic;

namespace Sinacor.Infra.Core.Licensing.Business
{
    public class Historico
    {
        #region Attributes
        private Data.Historico _resourceAccess;
        private object locker = new object();
        #endregion

        #region Constructor

        public Historico()
        {
            _resourceAccess = new Data.Historico();
        }

        #endregion

        #region Methods

        public List<Sinacor.Infra.Core.Licensing.Description> Selecionar(Sinacor.Infra.Core.Licensing.Description library)
        {
            return _resourceAccess.Selecionar(library);
        }

        public Sinacor.Infra.Core.Licensing.Description Incluir(Sinacor.Infra.Core.Licensing.Description library)
        {
            library.Id = _resourceAccess.SelecionarProximoIdHistorico();

            _resourceAccess.Incluir(library);

            return library;
        }

        private int SelecionarProximoIdHistorico()
        {
            int nextId = 0;

            lock (locker)
            {
                nextId = _resourceAccess.SelecionarProximoIdHistorico();
            }

            return nextId;
        }

        #endregion
    }
}
